package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.entity.h5.UserAddress;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.user.service.UserAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.http.cookie.SM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: UserAddressController
 * @Package: com.atguigu.spzx.user.controller
 * @Description 用户地址
 * @Author 孤妤
 * @Date: 2023/12/20 15:38
 */
@Tag(name = "用户地址")
@RestController
@RequestMapping("/api/user/userAddress")
public class UserAddressController {
    @Autowired
    private UserAddressService userAddressService;
    @GetMapping("/auth/findUserAddressList")
    @Operation(summary = "查询用户地址列表")
    public Result findUserAddressList(){
        List<UserAddress> userAddressList = userAddressService.findUserAddressList();
        return Result.build(userAddressList, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "查询最终收货地址")
    @GetMapping("/getUserAddress/{id}")
    public UserAddress findUserAddressById(@PathVariable Long id){
        return userAddressService.findUserAddressById(id);
    }
    @PutMapping("/auth/updateById")
    @Operation(summary = "修改用户地址")
    public Result changeUserAddress(@RequestBody UserAddress userAddress){
        userAddressService.changeUserAddress(userAddress);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "新增地址")
    @PostMapping("/auth/save")
    public Result addUserAddress(@RequestBody UserAddress userAddress){
        userAddressService.addUserAddress(userAddress);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "删除地址")
    @DeleteMapping("/auth/removeById/{id}")
    public Result removeUserAddressById(@PathVariable Long id){
        userAddressService.removeUserAddressById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
